package com.salon.client.beans;

import java.util.Date;

public class IncomeMaterialsBean extends ParentBean implements Comparable<IncomeMaterialsBean> {
	private int materialId;
	private int incomeId;
	
	//materials field
	private String name;
	private String code;
	private String desc;
	private boolean isConted;
	private int weight;
	
	//current income_material
	private float cost;
	private int count;
	
	private Date date;
	
	
	public Date getDate() {
		return date;
	}
	public void setDate(Date date) {
		this.date = date;
	}
	public boolean isConted() {
		return isConted;
	}
	public void setConted(boolean isConted) {
		this.isConted = isConted;
	}
	public int getWeight() {
		return weight;
	}
	public void setWeight(int weight) {
		this.weight = weight;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public int getMaterialId() {
		return materialId;
	}
	public void setMaterialId(int materialId) {
		this.materialId = materialId;
	}
	public int getIncomeId() {
		return incomeId;
	}
	public void setIncomeId(int incomeId) {
		this.incomeId = incomeId;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDesc() {
		return desc;
	}
	public void setDesc(String desc) {
		this.desc = desc;
	}
	public float getCost() {
		return cost;
	}
	public void setCost(float cost) {
		this.cost = cost;
	}
	public int getCount() {
		return count;
	}
	public void setCount(int count) {
		this.count = count;
	}
	
	public String getDisplayF() {
		String res = "";
		if ((code != null) && (!code.isEmpty())) {
			res += code;
			res += " ";
		}
		if (name != null) {
			res += name;
			res += " ";
		}
		res += getContedAsString() + " ";
		res += cost;
		res += " руб.";
		
		return res;
	}
	
	public String getIsContedAsString() {
		if (isConted) {
			return "штук";
		}
		else {
			return "грамм";
		}
	}
	
	public String getContedAsString() {
		return weight + " " + getIsContedAsString();
	}
	
	public String getCountWithString() {
		return count + " " + getIsContedAsString();
	}
	
	public IncomeMaterialsBean cloneMaterial() {
		IncomeMaterialsBean clone = new IncomeMaterialsBean();
		
		clone.setId(getId());
		clone.setCount(count);
		
		clone.setName(name);
		clone.setCode(code);
		clone.setWeight(weight);
		clone.setConted(isConted);
		
		clone.setIncomeId(incomeId);
		clone.setMaterialId(materialId);
		
		return clone;
	}
	@Override
	public int compareTo(IncomeMaterialsBean o) {
		if ((o == null) || (o.getDate() == null)) {
			return -1;
		}
		if (getDate() != null) {
			return o.getDate().compareTo(getDate());
		}
		return 1;
	}
}
